﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

namespace emulib
{
    class SQLiteHandler : IMmoDatabase
    {
        SQLiteConnection sqliteConnection;
        public Boolean Connect(ServerInfo sinfo)
        {
            //doesn't accept database for w/e reason
            //data source it is...
            WorkDirectory wd = new WorkDirectory(sinfo);
            sqliteConnection = new SQLiteConnection("data source=" + wd.GetFullPath(sinfo.dbInfo.sqldb) + ";");
            try
            {
                sqliteConnection.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine("Connection error: " + e.Message);
                return false;
            }
            return true;
        }
        public void Disconnect()
        {
            sqliteConnection.Close();
        }
        public IDataRecord Select(String what, String from, String where = null, String orderBy = null, Boolean direction = false, Int32 limitStart = -1, Int32 limitMax = -1)
        {
            return new SQLiteCommand().ExecuteReader();
        }
    }
}
